<template>
  <transition name="slide-up">
    <div
      class="setting-wrapper"
      v-show="ifThemeShow"
    >
      <div class="setting-theme c-clearfix">
        <div
          class="setting-theme-item"
          v-for="(item, index) in themeList"
          :key="index"
          @click="setTheme(index)"
        >
          <div
            class="preview"
            :style="{background: item.style.body.background}"
            :class="{'selected': index == defaultTheme}"
          ></div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'EbooksTheme',
  props: {
    themeList: Array,
    ifThemeShow: {
      type: Boolean,
      default: false
    },
    defaultTheme: Number,
  },
  data() {
    return {
    }
  },
  methods: {
    setTheme(index) {
      this.$emit('setTheme', index)
    },
  }
}
</script>

<style lang="less" scoped>
.setting-wrapper {
  position: fixed;
  bottom: 3.2rem;
  left: 0;
  width: 100%;
  height: 6.6rem;
  z-index: 102;
  background-color: #fff;
}
.setting-theme {
  width: 100%;
  height: 100%;
  border-bottom: 1px solid #f6f6f6;
  .setting-theme-item {
    float: left;
    width: 4rem;
    height: 3.3rem;
    &:nth-child(-n+4) {
      .preview {
        margin-top: 1rem;
      }
    }
    &:nth-child(-n+8):nth-child(n+5) {
      .preview {
        margin-top: .5rem;
      }
    }
    .preview {
      width: 1.8rem;
      height: 1.8rem;
      margin: 0 auto;
      border-radius: 50%;
      box-sizing: border-box;
      &.selected {
        border: 0.02rem solid #248AFD;
      }
    }
  }
}
.slide-down-enter,
.slide-down-leave-to {
  transform: translate3d(0, -100%, 0);
}
.slide-down-enter-to,
.slide-down-leave,
.slide-up-enter-to,
.slide-up-leave {
  transform: translate3d(0, 0, 0);
}
.slide-down-enter-active,
.slide-down-leave-active,
.slide-up-enter-active,
.slide-up-leave-active {
  transition: all 0.3s linear;
}
.slide-up-enter,
.slide-up-leave-to {
  transform: translate3d(0, 4.85rem, 0);
}
</style>